package leetcode.median;

import leetcode.base.TreeNode;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * ClassName: $113_PathSum
 * Description:
 * date: 2021-11-11 10:38
 *
 * @author liyifan
 */
public class $113_PathSum {

    List<List<Integer>> res = new LinkedList<>();

    Deque<Integer> path = new LinkedList<>();

    public List<List<Integer>> pathSum(TreeNode root, int targetSum) {
        dfs(root, targetSum);
        return res;
    }

    public void dfs(TreeNode root, int target) {
        if (root == null)
            return;
        path.offerLast(root.val);
        target -= root.val;
        if (root.left == null && root.right == null && target == 0)
            res.add(new LinkedList<>(path));

        dfs(root.left, target);
        dfs(root.right, target);
        path.pollLast();
    }
}
